package com.lz.autotest.project.testmanage.reportmanage.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.lz.autotest.common.aspectj.lang.annotation.Log;
import com.lz.autotest.common.aspectj.lang.enums.BusinessType;
import com.lz.autotest.common.entity.ResponseVo;
import com.lz.autotest.common.web.controller.BaseController;
import com.lz.autotest.common.web.page.TableDataInfo;
import com.lz.autotest.project.testmanage.infmanage.domain.SstInf;
import com.lz.autotest.project.testmanage.reportmanage.domain.SstInfReport;
import com.lz.autotest.project.testmanage.reportmanage.service.InfReportService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 接口信息
 *
 * @author lz
 */
@RestController
@RequestMapping("/infReport")
public class InfReportController extends BaseController {

    @Resource
    private InfReportService infReportService;

    Snowflake snowflake = IdUtil.getSnowflake(1, 2);

    /**
     * 请求
     */
    @PreAuthorize("@ss.hasPermi('test:infReport:save')")
    @PostMapping("/saveInfReport")
    public ResponseVo saveInfReport(@RequestBody SstInfReport sstInfReport) {
        int res = infReportService.saveInfReport(sstInfReport);
        return ResponseVo.success(res);
    }

    /**
     * 新增接口
     */
    @PreAuthorize("@ss.hasPermi('test:infManage:add')")
    @Log(title = "保存报告", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseVo add(@Validated @RequestBody SstInf sstInf) {
        sstInf.setReportId(snowflake.nextIdStr());
        int res = infReportService.saveInfReport(sstInf);
        return ResponseVo.success(res);
    }

    /**
     * 批量请求
     */
    @PreAuthorize("@ss.hasPermi('test:infReport:list')")
    @PostMapping("/queryInfReportList")
    public TableDataInfo queryInfReportList(@RequestBody SstInfReport sstInfReport) {
        startPage();
        List list = infReportService.queryInfReportList(sstInfReport);
        return getDataTable(list);
    }

    /**
     * 查询报告
     */
    @PreAuthorize("@ss.hasPermi('test:autoReport:list')")
    @RequestMapping("/queryAutoReportList")
    public TableDataInfo queryAutoReportList(@RequestParam Map<String, Object> param) {
        startPage();
        List list = infReportService.queryAutoReportList(param);
        return getDataTable(list);
    }

    /**
     * 删除报告
     */
    @PreAuthorize("@ss.hasPermi('test:autoReport:delete')")
    @RequestMapping("/deleteReport")
    public ResponseVo deleteAutoReport(@RequestBody List<String> ids) {
        infReportService.deleteReport(ids);
        return ResponseVo.success();
    }

    /**
     * 获取所有的版本号
     */
//    @PreAuthorize("@ss.hasPermi('test:autoReport:getVersion')")
    @GetMapping("/getVersion")
    public ResponseVo getVersion(@RequestParam Map<String, Object> param) {
        startPage();
        List<Map> vesions = infReportService.getVersion(param);
        return ResponseVo.success(vesions);
    }

    /**
     * 获取所有的版本号
     */
//    @PreAuthorize("@ss.hasPermi('test:autoReport:getReportByVersion')")
    @GetMapping("/getReportByVersion")
    public ResponseVo getReportByVersion(@RequestParam Map<String, Object> param) {
        startPage();
        List<SstInfReport> reports = infReportService.getReportByVersion(param);
        return ResponseVo.success(reports);
    }

}
